//
//  BaseAFNEngine.h
//  BeiGuo
//
//  Created by Yaping Liu on 16/5/7.
//  Copyright © 2016年 com.dlnu.*. All rights reserved.

//  本网络库是为了适应之前已经存的控制器，所以这里无法优化，无枚举，无驼峰命名，外部接口全部沿用之前的。

#import <Foundation/Foundation.h>
#import <AFNetworking.h>

@protocol ProgressCompletePercentageDelegate <NSObject>

- (void)completePercentageWithFloat:(CGFloat) progress;

@end

typedef void (^ResponseBlock)(id responseObject);
typedef void (^FinishBlock)(id responseObject);
typedef void (^AFNErrorBlock)(NSError* error);
typedef void (^DownloadBlock)(NSString *filePath);

@interface BaseEngine : NSObject

/**
 *  set request type get/post
 */
@property (strong,nonatomic) NSString *httpMethod;

@property (nonatomic) BOOL needLogin;
@property (nonatomic, assign) id<ProgressCompletePercentageDelegate> delegate;

/**
 *  upload data or fileUrl dictionary
 */
@property (strong,nonatomic) NSMutableDictionary *postDict;
@property (strong,nonatomic) NSMutableDictionary *postFileDict;


/**
 *  BaseAFNEngine Singleton
 *
 *  @return Singleton Object
 */
+ (BaseEngine *)sharedEngine;

- (void)setRequestPost;

/**
 *  http net request
 *  @return NSURLSessionDataTask Object
 */
- (NSURLSessionDataTask*)RunRequest:(NSMutableDictionary *)dict
                             path:(NSString *)path
                completionHandler:(ResponseBlock)completionBlock
                     errorHandler:(AFNErrorBlock)errorBlock
                    finishHandler:(FinishBlock)finishBlock;

/**
 *  https net request
 *  @return NSURLSessionDataTask Object
 */
- (NSURLSessionDataTask*)RunRequest:(NSMutableDictionary *)dict
                             path:(NSString *)path
                           useSSL:(BOOL)useSSL
                completionHandler:(ResponseBlock)completionBlock
                     errorHandler:(AFNErrorBlock)errorBlock
                    finishHandler:(FinishBlock)finishBlock;

/**
 *  download image
 *
 *  @param remoteURL       download address
 *  @param filePath        store resource to filePath when download is complete
 */
- (void)DownloadFileFrom:(NSString *)remoteURL
                  toFile:(NSString *)filePath
       completionHandler:(DownloadBlock)completionBlock
            errorHandler:(AFNErrorBlock)errorBlock;
/**
 *  cancel current net request
 *
 *  @param task current task
 */
- (void)cancelOperation:(NSURLSessionDataTask *)task;

@end
